<?php
set_time_limit(600);
date_default_timezone_set('Asia/Shanghai');
header("Content-type: application/json; charset=utf-8");

require_once('PhpSIP.class.php');
/* Sends NOTIFY to reset Linksys phone */

function dtmfINFO($str){
    global $api;
    if (empty($str) || empty($api))
        return;
    $dtmfone = str_split($str);
    foreach ($dtmfone as $one){
        usleep(500000);
        $res = $api->info("Signal=$one \r\nDuration=160 \r\n");
        //  echo $api->getCode()." return code \r\n";
    }
}
function dtmfRFC($str){
	global $api;
	if (empty($str) || empty($api))
		return;
	$dtmfone = str_split($str);
	foreach ($dtmfone as $one){
		$res = $api->sendRTPDTMF($one);
		usleep(20000);
	}
}

try{
  $api = new PhpSIP();
  $api->setDebug(TRUE);
  $api->setUsername('8888'); // authentication username
  $api->setPassword('741741741'); // authentication password
//   $api->setUsername('112233'); // authentication username
//   $api->setPassword('112233'); // authentication password
// ////  $api->setProxy('some_ip_here'); 
  $api->addHeader('Event: resync');
  $api->setMethod('INVITE');
  $api->setFrom('sip:8888@1.1.3.1:811');
  $api->setUri('sip:11888@1.1.3.1:811');
//   $api->setFrom('sip:112233@12.10.12.23:611');
//   $api->setUri('sip:6111888@12.10.12.23:611');
  $api->send();
if ($api->getCode()!="200")
    die("未正常处理请求，不能继续！ 返回状态码：".$api->getCode());
  sleep(6);
// //---sip info -------------------
//   dtmf("15827128933#");
//   sleep(11);
//   dtmf("791322141939506458#");
//---rfc2833 -------------------
$api->sendRTPDTMF(1);
sleep(2);
$api->sendRTPDTMF(1);
sleep(2);
$api->sendRTPDTMF(2);
sleep(2);
dtmfRFC("15827128933#");
sleep(2);
$api->sendRTPDTMF(1);
sleep(2);
$api->sendRTPDTMF(1);
sleep(2);
dtmfRFC("791322077857708457#");

$api->info("","BYE");

} catch (Exception $e) {
    echo $e;
}

?>
